#!/usr/bin/python
# -*- coding: utf-8 -*-
"""web main"""

from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler, Application
from tornado.escape import json_encode

#from rockps.auth import AuthHandler
from rockps.handlers.jsonphandler import JSONPHandler
from rockps.handlers.s8handler import S8ShortenHandler, S8ExpandHandler


class MainHandler(RequestHandler):
    def get(self):
        self.render("index.html")
        
class TestJSONP(JSONPHandler):
    def get(self):
        self.write(json_encode({'josnp-get': 'hello world.'}))
        
    def post(self):
        self.write(json_encode({'josnp-post': 'hello world.'}))


        
#class NewGameHandler(RequestHandler):
#    @authenticated
#    def get(self):
#        self.write('new game is created!')

settings = {
    "cookie_secret": "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
    "login_url": "/login",
    "template_path": "templates",
}

application = Application([
    (r"/", MainHandler),
    (r"/jsonp/helloword", TestJSONP),
    (r"/s8/s", S8ShortenHandler),
    (r"/s8/l", S8ExpandHandler),
#    (r"/new", NewGameHandler),
#    (r"/login", AuthHandler),
], **settings)


if __name__ == "__main__":
    print 'start'
    import logging
    logging.root.setLevel(logging.INFO)
    http_server = HTTPServer(application)
    http_server.listen(8081)
    IOLoop.instance().start()
